<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../easyUI/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../easyUI/themes/icon.css">
    <script type="text/javascript" src="../easyUI/jquery.min.js"></script>
    <script type="text/javascript" src="../easyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../addressIP.js"></script>
</head>
<body>
<table id="dg"></table>
<script type="application/javascript">
    var dg = $('#dg').datagrid({
        columns: [
            [
                {
                    field: 'labNum',
                    title: '门牌号',
                    width: '16.6%',
                    align: 'center'
                },
                {
                    field: 'labName',
                    title: '实验室名称',
                    width: '16.6%',
                    align: 'center'
                },
                {
                    field: 'laderName',
                    title: '负责人',
                    width: '16.6%',
                    align: 'center'
                },
                {
                    field: 'laderTeleNumber',
                    title: '负责人联系方式',
                    width: '16.6%',
                    align: 'center'
                },
                {
                    field: 'studentNumber',
                    title: '当前人数',
                    width: '16.6%',
                    align: 'center'
                }, {
                field: 'description',
                title: '简介',
                width: '16.6%',
                align: 'center',
                formatter: function(value) {
                    return "<span title='" + value + "'>"+value + "</span>";
                }
            }
            ]
        ]
    });
</script>
<script type="text/javascript">
    $(function() {
        var dg = $('#dg').datagrid({
            url: addressip + "/superGetLab",
            fitColumns: true,
            loadMsg: '数据加载中^_^',
            striped: true, //显示斑马线
            loadMsg: '等等我。。',
            idField: 'userID',
            rownumbers: true,
            pagination:true,
            fit: true,
            fitColumns: true,
            checkbox: true,
            autoRowHeight: false,
            emptyMsg: '暂无数据',
        });
        var fbutton = dg.datagrid('getPager');
        fbutton.pagination({
            buttons: [{
                iconCls: 'icon-add',
                handler: function() {
                    $('#teacheraddlab').dialog('open');
                    $('#teacheraddlab').window('center');
                }
            },{
                iconCls: 'icon-edit',
                handler: function() {
                    selectedrowss = $('#dg').datagrid('getSelections');
                    if(selectedrowss == null || selectedrowss.length == 0){
                        $.messager.alert('提示','请选择需要修改名称的实验室','info');
                    }else{
                        if(selectedrowss.length != 1){
                            $.messager.alert('提示','请选择一条数据修改','info');
                        }else{
                            $.messager.prompt('修改实验室名称', '输入实验室新名称:', function(r){
                                if(r!= null && r.length>0 && r.length<6){
                                    $.ajax({
                                        type: 'post',
                                        dataType: 'json',
                                        async:false,
                                        url: addressip+"/changeLabName",
                                        data:{
                                            teacherAccount: localStorage.getItem("superAccount"),
                                            password:localStorage.getItem("password"),
                                            labID: selectedrowss[0].labID,
                                            labName: r
                                        },
                                        success: function (node) {
                                            if(node == "success"){
                                                $.messager.alert("操作提示", "实验室名称修改成功", "warning");
                                                $("#dg").datagrid('reload');
                                            }else{
                                                if(node ==  "LabExist"){
                                                    $.messager.alert("操作提示", "提交信息有误", "warning");
                                                }else{
                                                    alert("未知错误");
                                                }
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                }
            },{
                iconCls: 'icon-clear',
                handler: function() {
                    $("#dg").datagrid('clearSelections');
                }
            }]
        });
    });
</script>
<div id="teacheraddlab" class="easyui-dialog" title="新增实验室" data-options="iconCls:'icon-save',closed:true" style="width:370px;height:450px;padding:10px">
    <div style="margin-bottom:20px">
        <input id="labnum" class="easyui-textbox" label="门牌号:" labelPosition="top" data-options="required:true, prompt:'请输入实验室门牌号：'"
               style="width:100%;">
    </div>
    <div style="margin-bottom:20px">
        <input id="labname" class="easyui-textbox" label="实验室名称:" labelPosition="top" data-options="required:true, prompt:'请输入实验室名称：'"
               style="width:100%;">
    </div>
    <div style="margin-bottom:20px">
        <input id="labdescription" class="easyui-textbox" label="实验室简介:" labelPosition="top" data-options="required:true, multiline:true, prompt:'50字以内：'"
               style="width:100%;height: 120px">
    </div>
    <br>
    <div style="margin-bottom:20px">
        <a href="" id="addLab" class="easyui-linkbutton" iconCls="icon-ok" style="width:100%;height:32px">创建</a>
    </div>
    <script>
        $("#addLab").click(function() {
            var lnum = $("#labnum").val().trim();
            var labname = $("#labname").val().trim();
            var labdescription = $("#labdescription").val().trim();
            if(lnum == null || labname == null || labdescription == null || lnum.length==0 || labname.length == 0 || labdescription.length == 0){
                $.messager.alert("提示", "请输入完整的正确实验室信息", "warning");
            }else{
                if(labdescription.length > 50){
                    $.messager.alert("操作提示", "实验室简介字数超过限制，请提炼精简后再提交", "warning");
                }else{
                    var teacherim = {};
                    teacherim.account = localStorage.getItem("superAccount");
                    teacherim.password = localStorage.getItem("password");
                    teacherim.teleNumber = localStorage.getItem("superAccount");
                    var labim = {};
                    labim.labName = labname;
                    labim.labNum = lnum;
                    labim.description = labdescription;
                    var paramlab = {};
                    paramlab.teacher = teacherim;
                    paramlab.lab = labim;
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        async:false,
                        url: addressip+"/CreatLab",
                        headers:{
                            'Content-Type':'application/json;charset=utf-8'
                        },
                        data:JSON.stringify(paramlab),
                        success: function (node) {
                            if(node == "success"){
                                $.messager.alert("操作提示", labname+"实验室创建成功", "warning");
                            }else{
                                if(node ==  "LabExist"){
                                    $.messager.alert("操作提示", "已存在重名实验室或重门牌号实验室", "warning");
                                }else{
                                    alert("未知错误");
                                }
                            }
                        }
                    });
                }
            }
        });
    </script>
</div>
</body>
</html>
